package com.personal.system.controller;

import com.personal.common.result.Result;
import com.personal.system.entity.sys.OnlineUser;
import com.personal.system.entity.RedisCacheInfoDTO;
import com.personal.system.entity.sys.ServerInfo;
import com.personal.system.service.sys.MonitorApplicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 监控
 *
 * @author valarchie
 */
@RestController
@RequestMapping("/monitor")
@RequiredArgsConstructor
@Api(tags = "监控Controller")
public class MonitorController {

    @NonNull
    private MonitorApplicationService monitorApplicationService;

    @ApiOperation("redis信息")
    @GetMapping("/cacheInfo")
    public Result getRedisCacheInfo() {
        RedisCacheInfoDTO redisCacheInfo = monitorApplicationService.getRedisCacheInfo();
        return Result.ok(redisCacheInfo);
    }

    @ApiOperation("服务信息")
    @GetMapping("/serverInfo")
    public Result getServerInfo() {
        ServerInfo serverInfo = monitorApplicationService.getServerInfo();
        return Result.ok(serverInfo);
    }

    /**
     * 获取在线用户列表
     * @return
     */
    @ApiOperation("在线用户列表")
    @GetMapping("/onlineUser/list")
    public Result list(String ipaddr, String userName) {
        List<OnlineUser> onlineUserList = monitorApplicationService.getOnlineUserList(userName, ipaddr);
        return Result.ok(onlineUserList);
    }

    /**
     * 强退用户
     */
    @DeleteMapping("/forceLogout/{userName}")
    public Result forceLogout(@PathVariable String userName) {

        return Result.ok(monitorApplicationService.forceLogout(userName));
    }


}
